package com.elinkway.infinitemovies.http.requesttask;

import android.content.Context;

import com.elinkway.infinitemovies.async.MoviesHttpAsyncTask;
import com.elinkway.infinitemovies.bean.CollectionListBean;
import com.elinkway.infinitemovies.http.api.MoviesHttpApi;
import com.elinkway.infinitemovies.http.parser.FavoriteListParser;
import com.elinkway.infinitemovies.http.requestInterface.RequestCommonInterface;
import com.lvideo.http.bean.LVideoDataHull;

/**
 * Created by xiaojian on 16-3-14.
 */

public class RequestGetFavoriteListTask extends MoviesHttpAsyncTask<CollectionListBean> {

    private Context context;
    private int index = 0;
    private int limit = 0;
    private RequestCommonInterface<CollectionListBean> mRequestCommonInterface;
    @Override
    public void netNull() {
        super.netNull();
        mRequestCommonInterface.netError(MoviesHttpApi.GET_FAVORITE_DATA);
    }

    @Override
    public void netErr(int updateId, String errMsg) {
        super.netErr(updateId, errMsg);
        mRequestCommonInterface.netError(MoviesHttpApi.GET_FAVORITE_DATA);
    }

    @Override
    public void dataNull(int updateId, String errMsg) {
        super.dataNull(updateId, errMsg);
        mRequestCommonInterface.requestFail(MoviesHttpApi.GET_FAVORITE_DATA);
    }

    public RequestGetFavoriteListTask(Context context, int index, int limit) {
        super(context);
        this.context = context;
        this.index = index;
        this.limit = limit;
    }

    public void setRequestListener(RequestCommonInterface<CollectionListBean> requestCommonInterface) {
        this.mRequestCommonInterface = requestCommonInterface;
    }

    @Override
    public LVideoDataHull<CollectionListBean> doInBackground() {
        LVideoDataHull<CollectionListBean> ret = MoviesHttpApi.favoriteDataRequest(
                new FavoriteListParser(), index, limit);
        return ret;
    }

    @Override
    public void onPostExecute(int updateId, CollectionListBean result) {
        if(result != null) {
            mRequestCommonInterface.requestSuccess(updateId, result, MoviesHttpApi.GET_FAVORITE_DATA);
        }else {

        }
    }
}